<?php
namespace app\daohang\controller;

use app\common\controller\Front;

class Tag extends Front
{
    //继承上级
    public function _initialize()
    {
        //过滤函数
        $this->request->filter('trim,strip_tags,htmlspecialchars');
        //继承上级
        parent::_initialize();
    }
    
    //daohang/tag/index/?id=88&pageNumber=2
    public function index()
    {
        if( isset($this->query['id']) ){
            $info = daohangTagId($this->query['id']);
        }elseif( isset($this->query['slug']) ){
            $info = daohangTagSlug($this->query['slug']);
        }elseif( isset($this->query['name']) ){
            $info = daohangTagName($this->query['name']);
        }else{
            $this->error(lang('mustIn'),'daohang/index/index');
        }
        if(!$info){
            $this->error(lang('empty'),'daohang/index/index');
        }
        //分页路径
        $info['pagePath']   = daohangUrlCategory($info,'[PAGE]');
        $info['pageSize']   = DcEmpty(intval(config('daohang.page_size')),20);
        $info['pageNumber'] = DcEmpty($this->query['pageNumber'], $this->site['page']);
        $info['sortName']   = 'info_order desc,info_update_time';
        $info['sortOrder']  = 'desc';
        //变量赋值
        $this->assign($info);
        //加载模板
        if($info['term_tpl']){
            return $this->fetch($info['term_tpl']);
        }
        return $this->fetch(DcEmpty($info['term_tpl'],'index'));
        
        //URL参数过滤
        $info['query'] = DcArrayEmpty($this->query);
        $info['query']['pagePath'] =  daohangUrl('daohang/tag/index',array_merge($info['query'],['pageNumber'=>'[PAGE]']));
        //数据查询参数
        $args = [];
        $args['cache']    = true;
        $args['status']   = 'normal';
        $args['term_id']  = $info['term_id'];
        $args['controll'] = ['in',['web','mini','mp']];
        $args['limit']    = daohangLimit($this->query['pageSize']);
        $args['page']     = DcEmpty($this->query['pageNumber'], $this->site['page']);
        $args['sort']     = DcEmpty($this->query['sortName'], 'info_update_time');
        $args['order']    = DcEmpty($this->query['sortOrder'], 'desc');
        if(in_array($this->query['controll'],['web','mini','mp'])){
            $args['controll'] = ['eq',$this->query['controll']];
        }
        //数据查询
        $info['list'] = daohangSelect($args);
        //dump($info);
        //变量赋值
        $this->assign($info);
        //加载模板
        return $this->fetch(DcEmpty($info['term_tpl'],'index'));
    }
    
    //daohang/tag/all/?pageNumber=2
    public function all()
    {
        $info = [];
        $info['seoTitle']       = daohangSeo(config('daohang.tag_title'));
        $info['seoKeywords']    = daohangSeo(config('daohang.tag_keywords'));
        $info['seoDescription'] = daohangSeo(config('daohang.tag_description'));
        $info['pagePath']       = daohangUrl('daohang/tag/all',['pageNumber'=>'[PAGE]']);
        $info['pageSize']       = DcEmpty(intval(config('daohang.page_size')),20);
        $info['pageNumber']     = DcEmpty($this->query['pageNumber'], $this->site['page']);
        $info['sortName']       = 'term_count desc,term_id';
        $info['sortOrder']      = 'desc';
        $this->assign($info);
        return $this->fetch();
    }
}